#include <gtk/gtk.h>
#include <stdio.h>

#include "gtkutils.h"

void sayHello() {
    printf("hello word\n");
}

enum {
    COMBO_BOX_TEXT,
};

// 构建数据
createTreeModelFunc(combo_box_modle) {
    GtkListStore *store = createListStore(1, G_TYPE_STRING);
    
    GtkTreeIter iter;
    listStoreAppend(store, &iter);
    listStoreSet(store, &iter, COMBO_BOX_TEXT, "Fuck");

    return GTK_TREE_MODEL(store);
}

// 数据处理
createCellLayoutDataFunc(combo_box_data) {
    GtkTreePath *path = createTreePathWithTreeModel(tree_model, iter);
    destroyTreePath(path);
}

static void activate(GtkApplication *app, gpointer user_data) {
    GtkWindow *window;

    window = createWindowWithTitleSize(app, "instruction-generater", 600, 300);

    GtkComboBox *choose = createComboBoxWithModelFuncUnref(combo_box_modle);
    setCellLayout(choose, createCellRendererText(), "text", COMBO_BOX_TEXT, combo_box_data, false);
    setComboBoxActive(choose, 0);

    GtkBox *mainBox = createBoxWithVerticalAppends(0, 
        createBoxWithHorizntalAppends(5, 
            choose,
            NULL
        )
    );
    setWidgetFullMargin(mainBox, 10);
    setWindowChild(window, mainBox);

    showWindow(window);
}

int	main(int argc, char **argv) {

    GtkApplication *app;
    int status;

    app = createApplicationConnectActivate("gtk.instruction.generater", 
                                G_APPLICATION_FLAGS_NONE, activate);
    // app = gtk_application_new("gtk.example.template", G_APPLICATION_FLAGS_NONE);
    // g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
    // status = g_application_run(G_APPLICATION(app), argc, argv);
    // g_object_unref(app);
    status = runApplication(app, argc, argv);
    objectUnref(app);

    return status;
}

